package com.jblapp.icu.sms;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.telephony.SmsManager;

public class SmsUtils {
	/**
	 * all
	 */
	private static final String SMS_URI_ALL = "content://sms/";
	/**
	 * inbox
	 */
	private static final String SMS_URI_INBOX = "content://sms/inbox";
	/**
	 * sent
	 */
	private static final String SMS_URI_SEND = "content://sms/sent";
	/**
	 * Draft
	 */
	private static final String SMS_URI_DRAFT = "content://sms/draft";
	private SmsManager smsManager = SmsManager.getDefault();
	private Context context = null;

	public SmsUtils(Context context) {
		this.context = context;
	}

	public void sendSmsMsg(String phoneNum, String textMsg) {
		smsManager.sendTextMessage(phoneNum, null, textMsg, null, null);
	}

	// public void readSmsMsg(String phoneNum) {
	// Cursor cursor = null;
	// cursor = context.getContentResolver().query(Uri.parse(SMS_URI_INBOX),
	// null, null, null, null);
	// cursor.moveToFirst();
	// }

	public String readSmsMsg(String tel) {
		Cursor cursor = null;
		String phoneNum = null;
		String smsMsgBody = null;
		// Long time = null;
		cursor = context.getContentResolver().query(Uri.parse(SMS_URI_INBOX),
				null, null, null, null);
		if (cursor.moveToFirst()) {
			phoneNum = cursor.getString(cursor.getColumnIndex("address"));
			smsMsgBody = cursor.getString(cursor.getColumnIndex("body"));
			// time = cursor.getLong(cursor.getColumnIndex("date"));
		}
		if (tel.equals(phoneNum)) {
			return smsMsgBody;
		} else
			return null;
	}
}
